package me.jessyan.mvparms.demo.mvp.ui.view;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * The author: Zhao X.H.
 * Creation time: 2018/5/11 ${time}
 */

public class SwipeRecyclerView extends RecyclerView {



    public SwipeRecyclerView(Context context) {
        super(context);
    }

    public SwipeRecyclerView(Context context,AttributeSet attrs) {
        super(context, attrs);
    }

    public SwipeRecyclerView(Context context,AttributeSet attrs, int defStyle) {
        super(context,attrs,defStyle);
    }
    float startX = 0;
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        getParent().requestDisallowInterceptTouchEvent(true);
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                startX = ev.getX();
                break;
            case MotionEvent.ACTION_MOVE:
                if(ev.getX()<startX)getParent().requestDisallowInterceptTouchEvent(true);
                else getParent().requestDisallowInterceptTouchEvent(false);
                break;
        }

        return super.dispatchTouchEvent(ev);
    }
}
